package com.hornsun.repository;

import com.hornsun.domain.dbo.Coupon;
import com.hornsun.domain.dbo.CouponExample;
import com.hornsun.repository.mapper.CouponMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by 编译中... on 2018/3/19.
 */
@Repository
public class CouponRepository {

    @Resource
    private CouponMapper couponMapper;

    public void insertCoupon(Coupon coupon){
        int count = couponMapper.insertSelective(coupon);
        if (count!=1){
            throw new IllegalArgumentException("insert coupon failed by coupon:"+coupon);
        }
    }

    public void updateCoupon(Coupon coupon){
        int count = couponMapper.updateByPrimaryKeySelective(coupon);
        if (count!=1){
            throw new IllegalArgumentException("update coupon failed by coupon:"+coupon);
        }
    }

    public void deleteCoupon(String guid){
        int count = couponMapper.deleteByPrimaryKey(guid);
        if (count!=1){
            throw new IllegalArgumentException("delete coupon failed by guid:"+guid);
        }
    }

    public List<Coupon> getCoupon(){
        return couponMapper.selectByExample(new CouponExample());
    }

    public Coupon queryByGuid(String couponGuid){
        return couponMapper.selectByPrimaryKey(couponGuid);
    }

}
